/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJPanel3.java
 *
 * Created on 10-Sep-2009, 00:16:54
 */

package com.gemom.gui;

import com.gemom.*;
import com.gemom.auction.*;
import java.util.*;

/**
 *
 * @author Yair D
 */
public class NewJPanel3 extends javax.swing.JPanel {

    /** Creates new form NewJPanel3 */
    public NewJPanel3( NewJPanel2 page2Panel) {

        //this.listBids=listBids;
        this.page2Panel=page2Panel;
        initComponents();
        this.jButton1search.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1Exhaus = new javax.swing.JScrollPane();
        jTextArea1Exhaus = new javax.swing.JTextArea();
        jScrollPane1Astar = new javax.swing.JScrollPane();
        jTextArea1Astar = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jButton1heu = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton1search = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();

        jScrollPane1Exhaus.setBorder(javax.swing.BorderFactory.createTitledBorder("EXHAUSTIVE SEARCH"));

        jTextArea1Exhaus.setColumns(20);
        jTextArea1Exhaus.setEditable(false);
        jTextArea1Exhaus.setRows(5);
        jTextArea1Exhaus.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jScrollPane1Exhaus.setViewportView(jTextArea1Exhaus);

        jScrollPane1Astar.setBorder(javax.swing.BorderFactory.createTitledBorder("IDA* SEARCH"));

        jTextArea1Astar.setColumns(20);
        jTextArea1Astar.setEditable(false);
        jTextArea1Astar.setRows(5);
        jTextArea1Astar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jScrollPane1Astar.setViewportView(jTextArea1Astar);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Heuristic factor"));

        jButton1heu.setText("OK");
        jButton1heu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1heuActionPerformed(evt);
            }
        });

        jTextField1.setText("0.90");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1heu)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1heu)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jButton1search.setText("Execute search");
        jButton1search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1searchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(476, 476, 476)
                .addComponent(jButton1search, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(479, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(128, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 1044, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1Exhaus, javax.swing.GroupLayout.PREFERRED_SIZE, 514, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1Astar, javax.swing.GroupLayout.PREFERRED_SIZE, 534, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(75, 75, 75))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1Exhaus)
                    .addComponent(jScrollPane1Astar, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE))
                .addGap(16, 16, 16)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1search)
                .addGap(233, 233, 233))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1heuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1heuActionPerformed
        // TODO add your handling code here:
        this.heuFactor= Double.parseDouble(this.jTextField1.getText());
        this.jButton1heu.setEnabled(false);
        this.jButton1search.setEnabled(true);
    }//GEN-LAST:event_jButton1heuActionPerformed

    private void jButton1searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1searchActionPerformed
        // TODO add your handling code here:

        listBids = this.page2Panel.getlistFBids();

         new Thread(new Runnable() {  public void run() {

            jTextArea1Exhaus.append(""+new Date()+"\n");
            searchTree tree = new searchTree(listBids);
            jTextArea1Exhaus.append("The winner path is:Exhaustive"+"\n");

            for(int i=0;i<tree.getWinnerPath().size();i++)
                     jTextArea1Exhaus.append(tree.getWinnerPath().get(i)+
                        "  Broker"+tree.getWinnerPath().get(i).getBrokerIdFlag()+"\n");
            jTextArea1Exhaus.append("The max path value is: "+tree.getTotalWinnerPath()+"\n");
            jTextArea1Exhaus.append("Number of nodes explored: "+tree.getNodesExplored()+"\n");
            jTextArea1Exhaus.append(""+new Date()+"\n");



            jTextArea1Astar.append(""+new Date()+"\n");
            searchTree2 tree2 = new searchTree2(listBids,heuFactor);
           jTextArea1Astar.append("The winner path is:IDA* search"+"\n");

            for(int i=0;i<tree2.getWinnerPath().size();i++)
                    jTextArea1Astar.append(tree2.getWinnerPath().get(i)+
                        "  Broker"+tree2.getWinnerPath().get(i).getBrokerIdFlag()+"\n");
            jTextArea1Astar.append("The max path value is: "+tree2.getTotalWinnerPath()+"\n");
            jTextArea1Astar.append("Number of nodes explored: "+tree2.getNodesExplored()+"\n");
           jTextArea1Astar.append(""+new Date()+"\n");



         }  }).start(); // start the thread

        





    }//GEN-LAST:event_jButton1searchActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1heu;
    private javax.swing.JButton jButton1search;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1Astar;
    private javax.swing.JScrollPane jScrollPane1Exhaus;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextArea1Astar;
    private javax.swing.JTextArea jTextArea1Exhaus;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

    NewJPanel2 page2Panel;
    private Vector<Bid> listBids;
    private double heuFactor=0.9;
}
